﻿@using Website.CRUDServices
@using Website.Models.Styling
@using Location = Website.Models.Domain.Location
@model Website.Models.ViewModels.ListView<Matchmaking>
@{
    this.ViewBag.Title = "Matchmaking";
    this.Layout = "~/Views/_Shared/_Layout.cshtml";
    var partners = this.ViewData["Partners"] as List<MatchmakingPartner> ?? new List<MatchmakingPartner>();
    var partnerTypes = this.ViewData["PartnerTypes"] as List<MatchmakingPartnerType> ?? new List<MatchmakingPartnerType>();
    var locations = this.ViewData["Locations"] as List<Location> ?? new List<Location>();

    var allProfiles = this.ViewData["Profiles"] as List<Profile>;
    var allProjects = this.ViewData["Projects"] as List<Project>;
}

<div class="float-right smallMarginBottom">
    <input type="button" onclick="@string.Format("location.href = '{0}';", this.Url.Action("NewMatchmaking"))" value="Opret nyt" class="" />
</div>
<table class="tableView">
    <tr>
        @foreach (TableViewHeaderItem item in this.Model.Header.Items)
        {
            <td>
                @Html.Partial("~/Views/_Shared/TableViewHeader.cshtml", item)
            </td>
        }
        <td></td><td></td>
    </tr>
    @if (this.Model != null)
    {
        foreach (Matchmaking mm in this.Model.List)
        {
        <tr>
            <td>@string.Format("{0:dd-MM-yyyy}", mm.Date)</td>
            
            <td>@mm.Name</td>

            <td style="font-size: 0.7em;">
                    @if (mm.Profiles != null && mm.Profiles.Any())
                    {
                        var test1 = allProfiles.Where(x => mm.Profiles.Contains(x.ID));
                        foreach (var att in allProfiles.Where(x => mm.Profiles.Contains(x.ID)).OrderBy(x => x.Name).Select(x => x.Name))
                        {
                            @att
                            <br />
                        }
                    }
                </td>
                <td style="font-size: 0.7em;">
                    @if (mm.OwnerProjects != null && mm.OwnerProjects.Any())
                    {
                        foreach (var proj in allProjects.Where(x => mm.OwnerProjects.Contains(x.ID)).OrderBy(x => x.Name).Select(x => x.Name))
                        {
                            @proj
                            <br />
                        }
                    }
                </td>
            <td>
                <a href="@Url.Action("UpdateMatchmaking", new { @Id = mm.ID })">
                <img src="@Url.Content("~/Content/ButtonIcons/tool_blue.png")" alt="Link"/></a>
            </td>
                        <td>
                <a href="@Url.Action("ViewMatchmaking", new { @Id = mm.ID })">
                <img src="@Url.Content("~/Content/ButtonIcons/notepad_blue.png")" alt="Link"/></a>
            </td>
        </tr>
        }
    }
    <tr>
        @Html.Partial("~/Views/_Shared/PagingArrows.cshtml", 
            Website.Models.Styling.PagingArrows.GetPagingArrowsFromHeader("Index", 2, this.Model)
        )
    </tr>
</table>
